//
//  ModelDictViewController.m
//  runtime
//
//  Created by dihuijun on 17/3/31.
//  Copyright © 2017年 Cycle. All rights reserved.
//

#import "ModelDictViewController.h"
#import "AddressModel.h"
#import "AddressModel2.h"
@interface ModelDictViewController ()
/**   datasource   */
@property (nonatomic, strong) NSMutableArray *datasource;
@end

@implementation ModelDictViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"modelWithDict";
    self.view.backgroundColor = [UIColor whiteColor];
    self.datasource = [NSMutableArray array];
    
    NSString *path = [[NSBundle mainBundle]pathForResource:@"address" ofType:@"plist"];
    NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:path];
    NSArray *dictArray = dictionary[@"address"];
    
    ///方式一
//    for (NSDictionary *di in dictArray) {
//        AddressModel *mode = [AddressModel resultModel1WithDict:di];
//        [self.datasource addObject:mode];
//    }
//    
//    //测试
//    for (NSInteger i = 0; i< self.datasource.count;i++) {
//        AddressModel *mode1 = self.datasource[0];
//        NSLog(@"第一层：%@",mode1.name);
//        for (NSInteger i = 0; i<mode1.sub.count; i++) {
//            AddressModel2 *mode2 = mode1.sub[0];
//            NSLog(@"第二层：%@  ==== %@  \n 数字：%@",mode2.name,mode2.zipcode,mode2.sub[1]);
//            
//            
//        }
//        
//    }
    ///方式二
      self.datasource =  [AddressModel mj_objectArrayWithKeyValuesArray:dictArray];
    NSLog(@"\n:  %@   \n\n %zd",self.datasource,self.datasource.count);
        for (NSInteger i = 0; i< self.datasource.count;i++) {
            AddressModel *mode1 = self.datasource[0];
            NSLog(@"第一层：%@",mode1.myname);
            for (NSInteger i = 0; i<mode1.sub.count; i++) {
                AddressModel2 *mode2 = mode1.sub[0];
                NSLog(@"第二层：%@  ==== %@  \n 数字：%@",mode2.name,mode2.zipcode,mode2.sub[1]);
    
    
            }
            
        }
    
//    NSLog(@"%@",dictArray[0][@"sub"][0]);
//    [CycleTool cycle_createPropertyWithDict:dictArray[1][@"sub"][0]];
   
}

@end
